package com.nsgf.library.ui.page;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;

import androidx.annotation.Nullable;

import com.kunminx.architecture.ui.page.DataBindingConfig;
import com.nsgf.library.BR;
import com.nsgf.library.R;
import com.nsgf.library.databinding.ActivityNsgfWebviewBinding;

public class WebViewRTCActivity extends BaseActivity {

    public WebViewRTCActivity() {
    }

    private StateHolder mState;

    @Override
    protected void initViewModel() {
        mState = getActivityScopeViewModel(StateHolder.class);
    }

    private ActivityNsgfWebviewBinding mBinding;

    @Override
    protected DataBindingConfig getDataBindingConfig() {
        return new DataBindingConfig(R.layout.activity_nsgf_webview, BR.vm, mState);
    }

    @SuppressLint("CheckResult")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mBinding = (ActivityNsgfWebviewBinding) getBinding();
        mBinding.webView.loadUrl(getIntent().getStringExtra("url"));
        mBinding.titlebar.getRoot().setVisibility(View.VISIBLE);
        mState.titleBar.set(getIntent().getStringExtra("title"));
        WebSettings mWebSettings = mBinding.webView.getWebView().getSettings();
        mWebSettings.setJavaScriptEnabled(true);//设置支持javaScript

        /* 设置可以访问文件 */
        mBinding.webView.getWebView().getSettings().setAllowFileAccess(true);
        // 是否允许通过file url加载的Javascript读取本地文件，默认值 false
        mBinding.webView.getWebView().getSettings().setAllowFileAccessFromFileURLs(true);
        // 是否允许通过file url加载的Javascript读取全部资源(包括文件,http,https)，默认值 false
        mBinding.webView.getWebView().getSettings().setAllowUniversalAccessFromFileURLs(true);

    }
}
